#!/usr/bin/make -f
#                                                       -*- makefile -*-
# debian/rules file for the Debian/GNU Linux centericq package
# Copyright 2002-2003 by Julien LEMOINE <speedblue@debian.org>

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


CXXFLAGS = -Wall -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CXXFLAGS += -O0
else
	CXXFLAGS += -O2
endif
config.status: configure
	dh_testdir
	CXXFLAGS="$(CXXFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) 	\
	  --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr 			\
          --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info

build: build-stamp

build-stamp:  config.status
	dh_testdir
	$(MAKE)
	mkdir doc && doxygen doxygen.cfg
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -rf build-stamp doc config.log config.sub config.guess
	-$(MAKE) distclean
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) install DESTDIR=$(CURDIR)/debian/happycoders-libsocket
	mv doc/html \
          $(CURDIR)/debian/happycoders-libsocket/usr/share/doc/happycoders-libsocket/doc-html
#deplace dev files in libsocket-dev packages
	mkdir -p $(CURDIR)/debian/happycoders-libsocket-dev/usr/lib/happycoders
	mkdir -p $(CURDIR)/debian/happycoders-libsocket-dev/usr/include/happycoders
	mv $(CURDIR)/debian/happycoders-libsocket/usr/include/happycoders/socket \
	$(CURDIR)/debian/happycoders-libsocket-dev/usr/include/happycoders
	mv $(CURDIR)/debian/happycoders-libsocket/usr/lib/happycoders/*.a	\
	$(CURDIR)/debian/happycoders-libsocket-dev/usr/lib/happycoders
	mv $(CURDIR)/debian/happycoders-libsocket/usr/lib/happycoders/*.la	\
	$(CURDIR)/debian/happycoders-libsocket-dev/usr/lib/happycoders

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install 
